from django.db import models
from login.models import MyUser
from course.models import Chapter


# Create your models here.
class ClassPoint(models.Model):
    point = models.FloatField(default=0)
    user = models.ForeignKey(MyUser, on_delete=models.CASCADE, default=1)
    CreatedAt = models.DateTimeField(max_length=200, auto_now_add=True)
    UpdatedAt = models.DateTimeField(max_length=200, auto_now=True)

    class Meta:
        verbose_name = u'互动打分'
        verbose_name_plural = u'互动打分'

    def __str__(self):
        return self.user.username


class AbsencePoint(models.Model):
    point = models.FloatField(default=0)
    user = models.ForeignKey(MyUser, on_delete=models.CASCADE, default=1)
    CreatedAt = models.DateTimeField(max_length=200, auto_now_add=True)
    UpdatedAt = models.DateTimeField(max_length=200, auto_now=True)

    class Meta:
        verbose_name = u'出勤打分'
        verbose_name_plural = u'出勤打分'

    def __str__(self):
        return self.user.username


class PaperPoint(models.Model):
    point = models.FloatField(default=0)
    user = models.ForeignKey(MyUser, on_delete=models.CASCADE, default=1)
    CreatedAt = models.DateTimeField(max_length=200, auto_now_add=True)
    UpdatedAt = models.DateTimeField(max_length=200, auto_now=True)

    class Meta:
        verbose_name = u'论文打分'
        verbose_name_plural = u'论文打分'

    def __str__(self):
        return self.user.username


class Homework(models.Model):
    name = models.CharField(max_length=200)
    description = models.CharField(max_length=2000)
    input_file = models.CharField(max_length=200)
    output_file = models.CharField(max_length=200)
    chapter = models.ForeignKey(Chapter, on_delete=models.CASCADE, default=1)
    CreatedAt = models.DateTimeField(max_length=200, auto_now_add=True)
    UpdatedAt = models.DateTimeField(max_length=200, auto_now=True)

    class Meta:
        verbose_name = u'课后作业'
        verbose_name_plural = u'课后作业'

    def __str__(self):
        return self.name


class HomeworkSubmit(models.Model):
    user = models.ForeignKey(MyUser, on_delete=models.CASCADE, default=1)
    work = models.ForeignKey(Homework, on_delete=models.CASCADE, default=1)
    code = models.CharField(max_length=2000)
    # 0 py 1 c++ 2 java
    code_type = models.IntegerField(default=0)
    # 0 ac 1 wa 2 re 3 tle 4 mle 5 others
    status = models.IntegerField(default=0)
    length = models.CharField(max_length=2000)
    info = models.CharField(max_length=2000)
    code_output = models.CharField(max_length=2000)
    run_time = models.CharField(max_length=2000)
    point = models.FloatField(default=-1)
    CreatedAt = models.DateTimeField(max_length=200, auto_now_add=True)
    UpdatedAt = models.DateTimeField(max_length=200, auto_now=True)

    class Meta:
        verbose_name = u'作业提交'
        verbose_name_plural = u'作业提交'

    def __str__(self):
        return self.user.username + '_' + self.work.name
